function model=init_params(data,flag,str)



% Random Initialization

if(flag==1)
   str2  = strcat('model',str,'.mat'); 
   model = load(str2);
else
    
    N      = size(data.dataw1(1).w,1);
    k      = data.k;
    k_hat  = data.k_hat;
    
    model.N        = N;
    model.alpha_01 = 3*rand(1,k)+1;
    model.sigma_01 = 1*rand(1,k)+0.001;
    
    model.alpha_02 = 3*rand(1,k_hat)+1;
    model.sigma_02 = 1*rand(1,k_hat)+0.001;
    
    
    model.eta=rand(k_hat, k)+0.01;
    model.eta=model.eta./repmat(sum(model.eta,2),1,k);
    
    model.r1 = data.r1;
    model.r2 = data.r2;
    
    for l=1:model.r1
        for i=1:k
            sz=size(data.dataw1(l).w,2);
            temp = rand(1,sz);
            model.beta_1(l,i).beta = temp/sum(temp);
        end
    end
    
    for r=1:model.r2
        for j=1:k_hat
            sz=size(data.dataw2(r).w,2);
            temp = rand(1,sz);
            model.beta_2(r,j).beta=temp/sum(temp);
        end
    end
    
    
    model.alpha_1 = 3*rand(N,k)+1;
    model.sigma_1 = 1*rand(N,k)+0.001;
    model.alpha_2 = 3*rand(N,k_hat)+1;
    model.sigma_2 = 1*rand(N,k_hat)+0.001;
    model.zeta_1  = 5*rand(1,N)+1;
    model.zeta_2  = 5*rand(1,N)+1;
    
    
    for n=1:N
        
        temp = rand(model.r1,k);
        temp = temp./repmat(sum(temp,2),1,k);
        model.phi_1(n,:,:)=temp;
        
        
        temp = rand(model.r2,k_hat);
        temp = temp./repmat(sum(temp,2),1,k_hat);
        model.phi_2(n,:,:)=temp;
        
    end
    
    model.MINVALUE = 0.0000001;
    model.sigmamin = 0.00001;
    model.lambda   = 0.01;
end
end
